<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>意达设计</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/dealer.css"/>

</head>
<body class="body">

<!-- header -->
<div class="pageheader"><a href="javascript:void(0);" onclick="api.closeWin();" class="return"></a><span>历史订单</span></div>

<!-- contact -->
<div class="odlist">
	<a class="ordliOn" href="javascript:void(0);" onclick="switchorder(1)">全部订单</a>
	<a href="javascript:void(0);" onclick="switchorder(2)">待发货</a>
	<a href="javascript:void(0);" onclick="switchorder(3)">已发货</a>
	<a href="javascript:void(0);" onclick="switchorder(4)">确认收货</a>
</div>

<div class="hr hrBG1"></div>

<div class="detailderlie" id='con'>
	<!-- <div class="derli">
      <div class="der_n1"><span>订单号：2018091117361529</span> <em>待发货</em></div>
      <div class="der_n2">
        <div class="derimg"><img src="../image/page/img-026.jpg"></div>
        <div class="deright">
          <a href="#">稻草人女包包2018新款复古手提包</a>
          <div class="derone"><span>颜色：红色、黄色、紫色</span> <em>￥15</em></div>
          <div class="dertwo"><span>数量： X10</span> <em>￥2199起</em></div>
        </div>
      </div>
      <div class="der_n3">
        <p>总计：¥<span>150.00</span></p>
        <div>
          <a class="alink2" href="javascript:void(0)">申请退单</a>
          <a class="alink2" href="javascript:void(0)">删除订单</a>
        </div>
      </div>
    </div>
    -->

</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/adaptive.js"></script>
<script type="text/javascript" src="../script/tabs.js"></script>
<script type="text/javascript">
    window['adaptive'].desinWidth = 750;
    window['adaptive'].baseFont = 28;
    window['adaptive'].maxWidth = 750;
    window['adaptive'].init();

var page=1;
var p='';
var para='';
var type='';

    apiready = function () {
        $api.fixStatusBar($api.dom('.header'));
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err){
            api.closeWidget();
        });
        api.showProgress();


        

        para=api.pageParam;
        
        type=para.type;

        
        qiehuan( type )
        

		    p={token:token,type:type,page:page};
        //alert(JSON.stringify(p));

        toDoRequest();



        api. addEventListener({name:'scrolltobottom'}, function(ret, err){
            
            toDoRequest();

        });

        
    };


    function switchorder(num) {
            page=1;
            type=num;
            //p={token:token,type:num,page:1};
            qiehuan(num);

            toDoRequest();
            
   	}
   	function qiehuan(index){
   		$('.odlist a').eq(index-1).addClass('ordliOn').siblings().removeClass('ordliOn');
    }

    function toDoRequest(){
         
        p={token:token,type:type,page:page};

        api.ajax({
            url: webSiteUrl+'/app/user/myorder',
            method: 'post',
            data: {
                values:p,
            }
        }, function(ret, err) {
            api.hideProgress();
            
            if(ret.code==200){
                
                //alert(ret.msg);return;
              
                html = "";
                var tj=ret.data;
                if(tj !=null){

               
                
                for(var i=0;i<tj.length;i++){


 html += '<div class="derli" id="p'+tj[i].id+'"><div class="der_n1"><span>订单号：'+tj[i].orderno+'</span><em>';
 if(tj[i].status==3){
  html += '已收货';
 }else if(tj[i].status==1){ 
  html += '待发货';
 }else if(tj[i].status==2){
  html += '已发货';
 }
  html += '</em></div><div class="der_n2"  onclick="orderdetail('+tj[i].id+')"><div class="derimg"><img src="'+webSiteUrl+tj[i].icon+'"></div><div class="deright"><a href="#">'+tj[i].name+'</a><div class="derone"><span>颜色：'+tj[i].color+'</span> <em>￥'+tj[i].price+'</em></div><div class="dertwo"><span>数量： X'+tj[i].num+'</span> <em></em></div></div></div><div class="der_n3"><p>总计：¥<span>'+tj[i].money+'</span></p><div>';

if(tj[i].status==5){

  if(tj[i].state==1){
      html += '<a class="alink2" href="javascript:void(0)" >等待退单</a>';
  }else if(tj[i].state==2){
      html += '<a class="alink2" href="javascript:void(0)" >完成退单</a>';
  }else if(tj[i].state==3){
      html += '<a class="alink2" href="javascript:void(0)" >驳回退单</a>';
  }else if(tj[i].state==0){
      html += '<a class="alink2" href="javascript:void(0)" onclick="backorder('+tj[i].id+')">申请退单</a>';
  }

  html += '<a class="alink2" href="javascript:void(0)" onclick="delorder('+tj[i].id+')">删除订单</a>';

 }else if(tj[i].status==1){
  html += '<a class="alink2" href="javascript:void(0)" onclick="xgorder('+tj[i].id+')">修改订单</a><a class="alink1" href="javascript:void(0)" onclick="overorder('+tj[i].id+')">确认收货</a>';

 }else if(tj[i].status==2){
  html += '<a class="alink1" href="javascript:void(0)" onclick="gopl('+tj[i].goodsid+','+tj[i].id+')">去评论</a><a class="alink1" href="javascript:void(0)" onclick="overorder('+tj[i].id+')">确认收货</a>';
 }

html += '</div></div></div>';
          }
          }

                        if(page==1){
                            $('#con').html(html);
                        }else{
                            $('#con').append(html);
                        }
                        page++;
                        //alert(JSON.stringify(p));
                    }else{
                        //alert(ret.msg);
                        if(page==1){
                            $('#con').html('<p style="text-align:center">暂无数据</p>');
                        }
                    }

    });
    }

   	function delorder(id){

     		api.confirm( {
    		  title: '提示',
    		  msg: '确认删除吗？',
    		  buttons: [ '确定', '取消' ]
    		}, function ( ret, err ) {
    		   var index = ret.buttonIndex;
    		   if ( index == 1 ) {

    			    var p={token:token,id:id};
    		   		api.ajax({
    		            url: webSiteUrl+'/app/user/delorder',
    		            method: 'post',
    		            data: {
    		                values:p,
    		            }
    		        }, function(ret, err) {
    		            api.hideProgress();
    		            
    		            if(ret.code==200){
    						       $('#p'+id).remove();
    		            }else{
    		            	 alert(ret.msg)
    		            }
    		      });
    		    }

    		})
   

   		
   	}
   	function overorder(id){
   		var p={token:token,id:id};
   		api.ajax({
            url: webSiteUrl+'/app/user/overorder',
            method: 'post',
            data: {
                values:p,
            }
        }, function(ret, err) {
            api.hideProgress();
            
            if(ret.code==200){
            	$('#p'+id).remove();
            }else{
            	alert(ret.msg);
            }
        })
   	}
    function gopl(id,oid){
      //alert(id)
      api.openWin({
            name: 'shopName',
            url: './pl.html',
            pageParam: {
                id: id,
                oid: oid,
            }
        });
    }
   	function backorder(id){
   		api.openWin({
            name: 'shopName',
            url: './backorder.html',
            pageParam: {
                id: id
            }
        });
   	}
   	function xgorder(id){
   		api.openWin({
            name: 'shopName',
            url: './xgorder.html',
            pageParam: {
                id: id
            }
        });
   	}
    function orderdetail(id){
   		api.openWin({
            name: 'shopName',
            url: './orderdetail.html',
            pageParam: {
                id: id
            }
        });
   	}            
</script>

</html>
